# cmake 最低版本要求
cmake_minimum_required(VERSION 2.8)
# 项目名称
project(sylar)

include(cmake/utils.cmake)

# 配置一些参数
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -rdynamic -O0 -ggdb -std=c++11 -Wall -Wno-deprecated -Werror -Wno-unused-function -Wno-builtin-macro-redefined")

# 指定头文件路径
include_directories(.)
include_directories(/apps/sylar/include)
link_directories(/apps/sylar/lib)

# 设置宏，指定项目链接库的源文件
set(LIB_SRC
    sylar/log.cc
    sylar/util.cc
    sylar/config.cc
    sylar/thread.cc
    sylar/fiber.cc
    sylar/scheduler.cc
    )

# 添加链接库，指定类型为动态链接库，并命名为 sylar
add_library(sylar SHARED ${LIB_SRC})
force_redefine_file_macro_for_sources(sylar) #__FILE__

# 查询动态链接库
find_library(YAMLCPP yaml-cpp)
find_library(PTHREAD pthread)

# 设置宏，指定链接库名
set(LIBS
		sylar
		pthread
		yaml-cpp
		)

# make 过程中输出的信息
message("***", ${LIBS})

# 添加可执行文件的目标文件名和源文件
add_executable(test tests/test.cc)
# 添加可执行文件的依赖
add_dependencies(test sylar)
force_redefine_file_macro_for_sources(test) #__FILE__
# 进行链接
target_link_libraries(test ${LIBS})

add_executable(test_config tests/test_config.cc)
add_dependencies(test_config sylar)
force_redefine_file_macro_for_sources(test_config) #__FILE__
target_link_libraries(test_config ${LIBS})

add_executable(test_thread tests/test_thread.cc)
add_dependencies(test_thread sylar)
force_redefine_file_macro_for_sources(test_thread) #__FILE__
target_link_libraries(test_thread ${LIBS})

add_executable(test_util tests/test_util.cc)
add_dependencies(test_util sylar)
force_redefine_file_macro_for_sources(test_util) #__FILE__
target_link_libraries(test_util ${LIBS})

add_executable(test_fiber tests/test_fiber.cc)
add_dependencies(test_fiber sylar)
force_redefine_file_macro_for_sources(test_fiber) #__FILE__
target_link_libraries(test_fiber ${LIBS})

add_executable(test_scheduler tests/test_scheduler.cc)
add_dependencies(test_scheduler sylar)
force_redefine_file_macro_for_sources(test_scheduler) #__FILE__
target_link_libraries(test_scheduler ${LIBS})





# 指定可执行文件的输出路劲
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# 指定生成库的输出路劲
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
